package com.lagou.work5.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class ClientReceiver implements Runnable{
    Socket socket;
    public ClientReceiver() {
    }
    public ClientReceiver(Socket socket){
        this.socket = socket;
    }
    @Override
    public void run() {

        try {
            // 获取输入流
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            while (true){
                // 时刻获取消息
                String chatMessage = bufferedReader.readLine();
                // 将消息输出在控制台
                System.out.println(chatMessage);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
